<template>
	<sys-container showBack :label="'会员套餐订单支付'" :withoutTop="true">
		<template v-slot:content>
			<view class="warp">
				<view class="tit">
					微信支付
				</view>
				<view class="payInfo">
					<view class="payType">
						{{formData.title}}-{{formData.cate_type}}
					</view>
					<view class="money">
						<text style="font-size:45rpx;">￥</text>
						<text
							style="font-size:72rpx;">{{Number(formData.price)*Number(formData.selectNum)}}</text>
					</view>
					<view class="getAccount">
						收款方：友卓消易云
					</view>
					<view class="surePay">
						<u-button 
							:custom-style="{width:'630rpx',height:'100rpx',borderRadius:'100rpx',background:'#D92928',color:'#fff'}" @click="createPayOrder">立即支付</u-button>
					</view>
				</view>
			</view>
		</template>
	</sys-container>
</template>

<script>
	import {buyOrder} from '@/globalApi/requestApi.js'
	export default {
		data() {
			return {
				formData: {}
			}
		},
		onLoad(options) {

			this.formData = JSON.parse(options.formData)
			// console.log(this.formData)
		},
		methods: {
			createPayOrder() {
				console.log(uni.getStorageSync('openId'))
				buyOrder({
					openid:uni.getStorageSync('openId'),
					member_ship_id:this.formData.memshipid,
					// memshipid :this.formData.memshipid 
				}).then(res=>{
					if(res.code==200){
						var obj = res.data
						this.$nextTick(()=>{
							console.log(obj)
							wx.requestPayment({
							  timeStamp: obj.timestamp.toString(),
							  nonceStr: obj.nonceStr.toString(),
							  package: obj.package.toString(),
							  signType: 'MD5',
							  paySign: obj.paySign.toString(),
							  success(res) {
							    // console.log(res)
								uni.showToast({
									title:'支付成功！',
									icon:'success'
								})
								setTimeout(function(){
									uni.navigateBack({
										delta:-2
									})
								},2000)
							  },
							  fail(res) {
							    uni.showToast({
							    	title:'支付失败！',
							    	icon:'error'
							    })
							    setTimeout(function(){
							    	uni.navigateBack({
							    		delta:-1
							    	})
							    },2000)
							  }
							})
						})
						
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.warp {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		padding: 0 30rpx;
		box-sizing: border-box;
		align-items: center;
		justify-content: flex-start;
		background: #F6F6F6;

		.tit {
			padding: 28rpx 0;
			box-sizing: border-box;
			font-size: 36rpx;
			font-weight: 400;
			color: #222222;
		}

		.payInfo {
			width: 100%;
			background: #fff;
			padding: 0 30rpx;

			.payType {
				padding: 33rpx 0;
				box-sizing: border-box;
				border-bottom: 1rpx solid #DCDCDC;
			}

			.money {
				width: 100%;
				text-align: center;
				margin: 70rpx 0 50rpx;
				font-weight: 400;
				color: #DA2627;
			}

			.getAccount {
				width: 100%;
				margin-bottom: 68rpx;
				text-align: center;
			}

			.surePay {
				width: 100%;
				display: flex;
				justify-content: center;
				margin-bottom: 60rpx
			}
		}

	}
</style>